cmake_minimum_required(VERSION 3.22)
project(Sofa.GL.Component.Shader LANGUAGES CXX)

set(SOFAGLCOMPONENTONSHADER_SOURCE_DIR "src/sofa/gl/component/shader")

set(HEADER_FILES
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/config.h.in
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/init.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/CompositingVisualLoop.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/LightManager.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/Light.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OrderIndependentTransparencyManager.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglOITShader.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglAttribute.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglAttribute.inl
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShader.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShaderMacro.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShaderVisualModel.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShadowShader.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglTexture.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglTexturePointer.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglVariable.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglVariable.inl
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglRenderingSRGB.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/PostProcessManager.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/VisualManagerPass.h
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/VisualManagerSecondaryPass.h
)

set(SOURCE_FILES
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/init.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/CompositingVisualLoop.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/Light.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/LightManager.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OrderIndependentTransparencyManager.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglOITShader.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglAttribute.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShader.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShaderMacro.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShaderVisualModel.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglShadowShader.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglTexture.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglTexturePointer.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglVariable.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/OglRenderingSRGB.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/PostProcessManager.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/VisualManagerPass.cpp
    ${SOFAGLCOMPONENTONSHADER_SOURCE_DIR}/VisualManagerSecondaryPass.cpp
)

sofa_find_package(Sofa.Simulation.Core REQUIRED)
sofa_find_package(Sofa.GL REQUIRED)
sofa_find_package(Sofa.GL.Component.Rendering3D REQUIRED) # for OglModel

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Core Sofa.GL Sofa.GL.Component.Rendering3D)

sofa_create_package_with_targets(
    PACKAGE_NAME ${PROJECT_NAME}
    PACKAGE_VERSION ${Sofa_VERSION}
    TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
    INCLUDE_SOURCE_DIR "src"
    INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
)

# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
cmake_dependent_option(SOFA_GL_COMPONENT_SHADER_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
if(SOFA_GL_COMPONENT_SHADER_BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()
